package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Publish;

import android.os.Bundle;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Publish.Adapter.CourseListAdapter;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Publish.ItemBean.ListCourse;

import java.util.ArrayList;
import java.util.List;

public class PublishHomeFragment extends BaseBackFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;
    private List<ListCourse> list;
    View view;
    ImageView iv_back;
    RecyclerView rv_CourseList;
    LinearLayout ll_CreateHomework,ll_exam,ll_task,ll_Notification,ll_AddCourse;
    public PublishHomeFragment() {
    }

    public static PublishHomeFragment newInstance(String param1, String param2) {
        PublishHomeFragment fragment = new PublishHomeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.course_publish_home_fragment, container, false);
        ll_CreateHomework = view.findViewById(R.id.ll_CreateHomework);
        ll_exam = view.findViewById(R.id.ll_exam);
        ll_task = view.findViewById(R.id.ll_task);
        iv_back = view.findViewById(R.id.iv_back);

        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigateUp();
            }
        });

        ll_CreateHomework.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                PublishHomeFragmentDirections.ActionPublishHomeFragmentToCreateHomeFragment action = PublishHomeFragmentDirections.actionPublishHomeFragmentToCreateHomeFragment();
                action.setLabel("HomeWork");
                navController.navigate(action);
            }
        });

        ll_exam.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                PublishHomeFragmentDirections.ActionPublishHomeFragmentToCreateHomeFragment action = PublishHomeFragmentDirections.actionPublishHomeFragmentToCreateHomeFragment();
                action.setLabel("exam");
                navController.navigate(action);
            }
        });

        ll_task.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                PublishHomeFragmentDirections.ActionPublishHomeFragmentToCreateHomeFragment action = PublishHomeFragmentDirections.actionPublishHomeFragmentToCreateHomeFragment();
                action.setLabel("task");
                navController.navigate(action);
            }
        });
        ll_Notification = view.findViewById(R.id.ll_Notification);
        ll_Notification.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController .navigate(R.id.action_publishHomeFragment_to_notificationHomeFragment);
            }
        });
        rv_CourseList = view.findViewById(R.id.rv_CourseList);
        list = new ArrayList<>();
        InitData();
        rv_CourseList.setLayoutManager(new LinearLayoutManager(getContext()));
        rv_CourseList.setAdapter(new CourseListAdapter(list));

        ll_AddCourse = view.findViewById(R.id.ll_AddCourse);
        if(!list.isEmpty()){
            ll_AddCourse.setVisibility(View.GONE);
        }
        return view;
    }
    private void InitData() {
        list.add(new ListCourse(R.drawable.homework_ranking,"张三","2023-05-05","计算机科学技术"));
        list.add(new ListCourse(R.drawable.homework_ranking,"张三","2023-05-05","课程名称"));
        list.add(new ListCourse(R.drawable.homework_ranking,"张三","2023-05-05","课程名称"));
    }
}